#include <iostream>
using namespace std;

const int kMaxN = 5e4 + 10;

int a[kMaxN], sum[kMaxN];

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, ans = 0;
  int pos[7];

  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum[i] = (sum[i - 1] + a[i]) % 7;
  }
  for (int i = 0; i < 7; i++) {
    pos[i] = 1e9;
  }
  pos[0] = 0;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, i - pos[sum[i]]);
    pos[sum[i]] = min(pos[sum[i]], i);
  }
  cout << ans << "\n";
  return 0;
}